// zoj1992
// 题意：给定一个n(<=200)个点, m(<=1000)条边的混合图（有无向边也有有向边），
//       问是否有一个欧拉回路（每条边都经过一次）。
//
// 题解：首先不管边的方向，如果一个点的度数为奇数肯定无解。
//       然后我们要想每个点出边和入边想等，这有点像网络流。我们将一个点i拆
//       成两个点i1, i2，i1表示入，i2表示出。增加弧i2->i1，容量正无穷。
//       对于每条无向边(i, j)，连i2->j1以及j2->i1，容量都是1。
//       对于每条有向边(i, j)，只需要连i2->j1，容量为1就行，下界为1。
//       所有i1都向T连degree[i]/2的容量的边，S向所有i2连degree[i]/2的边。
//
//       然后跑一遍有源汇的上下界最大流，如果最大流等于边数（度数一半），
//       就有解。
//
// run: $exec < input
#include <iostream>
#include <vector>
#include <queue>
#include <limits>

template <class T>
struct dinic
{
	typedef T value_type;
	typedef int size_type;
	typedef std::vector<size_type>::iterator edge_iter;

	struct edge {
		size_type from, to;
		value_type capacity, flow;
	};

	dinic(size_type num) : size(num)
	{
		graph.resize(num);	//[0, num)
		dist.resize(num);	//[0, num)
	}

	void add_edge(int u, int v, value_type cap = capacity_inf)
	{
		edge tmp;
		tmp.from = u; tmp.to = v; tmp.capacity = cap; tmp.flow = 0;
		edges.push_back(tmp);
		graph[u].push_back(edges.size() - 1);

		tmp.from = v; tmp.to = u; tmp.capacity = 0; tmp.flow = 0;
		edges.push_back(tmp);
		graph[v].push_back(edges.size() - 1);
	}

	bool bfs_label(size_type source, size_type target)
	{
		std::fill(dist.begin(), dist.end(), -1);
		std::queue<size_type> q;
		q.push(source);
		dist[source] = 0;
		while (!q.empty()) {
			size_type now = q.front();
			q.pop();
			for (edge_iter it = graph[now].begin(); it != graph[now].end(); ++it) {
				edge e = edges[*it];
				if (dist[e.to] == -1 && e.capacity > e.flow) {
					q.push(e.to);
					dist[e.to] = dist[now] + 1;
				}
			}
		}
		return dist[target] != -1;
	}

	value_type dfs(size_type v, size_type target, value_type f)
	{
		if (v == target || !f) return f;
		value_type block_flow = 0;
		for (edge_iter it = graph[v].begin(); it != graph[v].end(); ++it) {
			edge & e = edges[*it];
			if (e.capacity > e.flow && dist[e.to] == dist[v] + 1) {
				value_type tmp = dfs(e.to, target,
						std::min(e.capacity - e.flow, f - block_flow));
				block_flow += tmp;
				e.flow += tmp;
				edges[(*it) ^ 1].flow -= tmp;
			}
		}
		if (!block_flow) dist[v] = -1;
		return block_flow;
	}

	value_type max_flow(size_type source, size_type target)
	{
		value_type flow = 0;
		for (int tmp; bfs_label(source, target); )
			while ((tmp = dfs(source, target, capacity_inf))) flow += tmp;
		return flow;
	}

//private:
	value_type static const capacity_inf = 1 << 28;
	size_type size;
	std::vector<int> dist;
	std::vector<edge> edges;
	std::vector<std::vector<size_type> > graph;
};

int const maxn = 507;
int degree[maxn];
int n, m;

void init()
{
	for (int i = 1; i <= n; i++)
		degree[i] = 0;
}

int main()
{
	/*
	dinic<int> dd(10);
	dd.add_edge(0, 2);
	dd.add_edge(3, 1);
	dd.add_edge(4, 3, 2);
	dd.add_edge(2, 5, 2);
	dd.add_edge(2, 3, 0);

	dd.add_edge(5, 4);
	std::cout << dd.max_flow(4, 5) << '\n';

	dd.add_edge(4, 0);
	dd.add_edge(1, 5);

//	std::cout << dd.max_flow(0, 1) << '\n';
	return 0;
	*/

	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> m;
		init();
		int s = 0, t = 2 * n + 1;
		int ns = t + 1, nt = t + 2;
		dinic<int> d(nt + 4);
		for (int i = 1; i <= n; i++)
			d.add_edge(n + i, i);
		int sum = 0;
		for (int i = 0, x, y, td; i < m; i++) {
			std::cin >> x >> y >> td;
			degree[x]++; degree[y]++;
			if (td == 1) {
				d.add_edge(x, n + y, 0);
				d.add_edge(ns, n + y, 1);
				d.add_edge(x, nt, 1);
				sum++;
			} else {
				d.add_edge(x, n + y, 1);
				d.add_edge(y, n + x, 1);
			}
		}

		bool ok = true;
		for (int i = 1; i <= n; i++) {
			if (degree[i] & 1) { ok = false; break; }
			d.add_edge(s, i, degree[i] / 2);
			d.add_edge(n + i, t, degree[i] / 2);
		}
		if (!ok) { std::cout << "impossible\n"; continue; }

		d.add_edge(t, s);
		int tflow = d.max_flow(ns, nt);
		if (tflow != sum) { std::cout << "impossible\n"; continue; }
		d.add_edge(ns, s);
		d.add_edge(t, nt);
		int flow = d.max_flow(ns, nt);

//		for (auto i : d.edges) std::cout << "from = " << i.from << "  to = " << i.to << "  cap = " << i.capacity << "  flow = " << i.flow << '\n';
//		std::cout << flow << '\n';
		std::cout << (flow == m ? "possible" : "impossible") << '\n';
	}
}

